<?php

define('SCRIPT_FS_DIR',

	dirname(__FILE__) . DIRECTORY_SEPARATOR . 'src'

);

if (isset($_GET['minified']) && $_GET['minified'] == 'true'){

	$scriptTags = '<script type="text/javascript" src="out/all.js"></script>';

} else {

	$jsListFile = 'js-list.txt';


	$fp = fopen($jsListFile, 'r');
	$contents = fread ( $fp , filesize($jsListFile) );
	fclose($fp);

	$lines = preg_split('/(\r\n|\n)+/', $contents);

	$scriptTags = array();

	foreach ($lines as $line) {

		$line = preg_replace(
			array(
				"/^\;.*$/",
				"/^\s*(.*)\s*$/"
			),

			array(
				'',
				'$1'
			),

			$line
		);

		// create script tag for this line
		if ($line) {

			$fs_path = SCRIPT_FS_DIR . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $line);

			if (!is_file($fs_path)) {

				continue;

			}

			$scriptTags[] = '<script type="text/javascript" src="src/' . $line . '"></script>';

			// add more.js in case it exist
			$more = preg_replace('/\.js$/i', '', $fs_path) . DIRECTORY_SEPARATOR . 'more.js';

			if (is_file($more)) {

				$more_url = str_replace(

					DIRECTORY_SEPARATOR,

					'/',

					substr($more, strlen(SCRIPT_FS_DIR))

				);

				$scriptTags[] = '<script type="text/javascript" src="src' . $more_url . '"></script>';

			}

		}

	}

	$scriptTags = implode("\r\n", $scriptTags) . "\r\n";

}


/**
 *	create nodes
 */
$contents = '';

//$template = '<div{attr}>{content}</div>';
//
//$count = 50;
//
//for($c = 0; $count--;){
//
//	$c++;
//
//	$replacements = array(
//
//		'/\{attr\}/' => ' class="ct count' . $c . '" id="id' . $c . '" name="name' . $c . '" test="test"',
//
//		'/\{content\}/' => '
//		row ' . $c . '
//		<span>test span</span>
//		<br />
//		<b lang="fr" id="fr' . $c .'">test b</b>
//		<br />
//		test textnode
//		<div lang="fr-be"  id="fr-be' . $c .'">
//			<span>inner span</span>
//
//			<hr />
//		</div>
//		',
//
//	);
//
//	$contents .= preg_replace(
//
//		array_keys( $replacements ),
//
//		array_values( $replacements ),
//
//		$template
//
//	);
//
//}
//
//$contents = '<div id="query-sample">' . $contents . '</div>';


/**
 *	output HTML
 */
echo <<<HTMLDOC
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Jx</title>
	<!-- <link rel="stylesheet" type="text/css" href="styles/base/jx.css" /> -->

{$scriptTags}

</head>
<body style="margin: 10px 20px 30px 40px">

	{$contents}


	<script type="text/javascript" src="test.js" checked="checked"></script>




</body>
</html>

HTMLDOC;
